package com.yunwaikeji.gy_tool_library.utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class GYClassUtils {
    public static <T> List<Class<T>> getGenericSuperclassList(Object tClass) {
        List<Class<T>> classList = new ArrayList<>();
        Type type = tClass.getClass().getGenericSuperclass();
        if (type != null) {
            Type[] types = ((ParameterizedType) type).getActualTypeArguments();
            for (Type type1 : types) {
                classList.add((Class<T>) type1);
            }
        }
        return classList;
    }

    public static <T> Class<T> getGenericSuperclass(Object tClass, int index) {
        return (Class<T>) getGenericSuperclassList(tClass).get(index);
    }
}
